#include "ms618_alghighdatum.h"

using namespace MeasurE618;
AlgHighDatum::AlgHighDatum(int i):AlgBase(i)
{

}

void AlgHighDatum::operator()(cv::Mat &srcImg, int id)
{
//    qDebug() << " ";
    //SE4和SE7结果输出输入到 FindDatumPoint函数获得基准 setup2
    //int FindDatumPoint(vector<cv::Point2f> xpts, vector<cv::Point2f> ypts, vector<cv::Point2f>& datumpts);

    std::vector<std::vector<cv::Point2f>> resptVec;
    //resptVec.resize(2);
    for(auto i=32;i<34;i++)
    {
        std::vector<int> tparas;
        for(auto j=0;j< m_dataAllVec[i].m_edgeParam.cols;j++)
        {
            tparas.push_back(m_dataAllVec[i].m_edgeParam.at<int>(i-32,j));
        }
        std::vector<cv::Rect> rangVec;
        TemplateMatch(srcImg,m_dataAllVec[i],rangVec);
        cv::Mat imgt=srcImg(rangVec[0]).clone();
        std::vector<cv::Point2f> contours;
        edgedetect obj;
        if(i==32)
        {obj.NewKirschEdgeOuter(imgt,tparas,contours);}
        else
        {obj.LDmeasure(imgt,tparas,contours);}
        ImageCoordinateTransformation(contours,rangVec);

        resptVec.push_back(contours);
//        for(auto &elem:contours)
//        {
//            cv::Point2f ptsIn(static_cast<float>(elem.x),static_cast<float>(elem.y)),ptsOut;
//            CoordinateTransformation(datumBackVec[id],ptsIn,ptsOut);
//            resptVec[i-38].push_back(ptsOut);
//        }
    }
    vector<cv::Point2f> datum;
    edgedetect obj;
    obj.FindDatumPoint(resptVec[0],resptVec[1],datum);
    AlgBase::datumFrontVec[id]=datum;
    AlgBase::flagfrontVec[id] = true;
    (*AlgBase::cvarptrfrontVec[id]).notify_all();


   // cout<<datum[0].x<<endl;
    qDebug() << " ";

}
